package com.woniu.service.Impl;

import com.woniu.dao.ScoreCardDao;
import com.woniu.entity.ScoreCard;
import com.woniu.service.CreditScoreCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 评分卡
 * 陈泓霖
 * */
@Service
public class CreditScoreCardServiceImpl implements CreditScoreCardService {
    @Autowired
    ScoreCardDao scoreCardDao;

    @Override
    public List<ScoreCard> findScoreList() {
        return scoreCardDao.findScoreList();
    }

    @Override
    public int updateCreScorecard(ScoreCard scoreCard) {
        return scoreCardDao.updateScorecard(scoreCard);
    }

    @Override
    public int pattern1() {
       int count = 0;
        List<ScoreCard> list = scoreCardDao.findScoreList();
        for(ScoreCard scoreCard : list){
            Integer value = scoreCard.getScoreValue();
            if(value<0){
                value *= 2;
            }else{
                value = (int)(value * 0.5);
            }
            scoreCard.setScoreValue(value);
           count += updateCreScorecard(scoreCard);
        }

        return count;
    }


    @Override
    public int pattern2() {
        int count = 0;
        List<ScoreCard> list = scoreCardDao.findScoreList();
        for(ScoreCard scoreCard : list){
            Integer value = scoreCard.getScoreValue();
            if(value<0){
                value = (int)(value * 0.5);
            }else{
                value *= 2;
            }
            scoreCard.setScoreValue(value);
            count += updateCreScorecard(scoreCard);
        }

        return count;
    }

}
